<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Attribute::Handlers - Simpler definition of attribute handlers - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Attribute::Handlers">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Attribute::Handlers.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Attribute::Handlers">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Attribute::Handlers">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Attribute::Handlers">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Attribute::Handlers">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Attribute::Handlers">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Attribute::Handlers">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Attribute::Handlers">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Attribute::Handlers">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Attribute::Handlers">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Attribute::Handlers">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Attribute::Handlers">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Attribute::Handlers">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Attribute::Handlers">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Attribute::Handlers">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Attribute::Handlers">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Attribute::Handlers">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Attribute::Handlers">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Attribute::Handlers">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Attribute::Handlers">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Attribute::Handlers">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Attribute::Handlers">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Attribute::Handlers">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Attribute::Handlers">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Attribute::Handlers">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Attribute::Handlers">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Attribute::Handlers">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Attribute::Handlers">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Attribute::Handlers">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Attribute::Handlers">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Attribute::Handlers">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Attribute::Handlers">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Attribute::Handlers">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Attribute::Handlers">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Attribute::Handlers">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Attribute::Handlers">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Attribute::Handlers">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Attribute::Handlers">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Attribute::Handlers">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Attribute::Handlers">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Attribute::Handlers">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Attribute::Handlers">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Attribute::Handlers">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Attribute::Handlers">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Attribute::Handlers">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Attribute::Handlers">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Attribute::Handlers">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Attribute::Handlers">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Attribute::Handlers">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Attribute::Handlers">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Attribute::Handlers">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Attribute::Handlers">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Attribute::Handlers">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Attribute::Handlers">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Attribute::Handlers">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Attribute::Handlers">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Attribute::Handlers">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Attribute::Handlers">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Attribute::Handlers">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Attribute::Handlers">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Attribute::Handlers">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Attribute::Handlers">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Attribute::Handlers">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Attribute::Handlers">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Attribute::Handlers">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Attribute::Handlers">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Attribute::Handlers">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Attribute::Handlers">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Attribute::Handlers">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Attribute::Handlers">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Attribute::Handlers">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Attribute::Handlers">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Attribute::Handlers">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Attribute::Handlers">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Attribute::Handlers">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Attribute::Handlers">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Attribute::Handlers">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Attribute::Handlers">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Attribute::Handlers">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Attribute::Handlers">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Attribute::Handlers">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Attribute::Handlers.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Attribute::Handlers">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Attribute::Handlers">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Attribute::Handlers">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Attribute::Handlers">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Attribute::Handlers">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Attribute::Handlers">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Attribute::Handlers">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Attribute::Handlers">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Attribute::Handlers">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Attribute::Handlers">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Attribute::Handlers">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Attribute::Handlers">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Attribute::Handlers">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Attribute::Handlers">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Attribute::Handlers">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Attribute::Handlers">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Attribute::Handlers">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Attribute::Handlers">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Attribute::Handlers">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Attribute::Handlers">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Attribute::Handlers">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Attribute::Handlers">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Attribute::Handlers">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Attribute::Handlers">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Attribute::Handlers">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Attribute::Handlers">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Attribute::Handlers">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Attribute::Handlers">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Attribute::Handlers">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Attribute::Handlers">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Attribute::Handlers">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Attribute::Handlers">5.35.1</a>
          <a class="dropdown-item active" href="./Attribute::Handlers.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Attribute::Handlers.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./Attribute::Handlers.html">Attribute::Handlers</a>
          <div id="more">
            (<a href="./Attribute::Handlers.txt">source</a>,
            <a href="https://metacpan.org/pod/Attribute::Handlers">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.01</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#VERSION">VERSION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Typed-lexicals">Typed lexicals</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Type-specific-attribute-handlers">Type-specific attribute handlers</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Non-interpretive-attribute-handlers">Non-interpretive attribute handlers</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Phase-specific-attribute-handlers">Phase-specific attribute handlers</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Attributes-as-tie-interfaces">Attributes as tie interfaces</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#Passing-the-tied-object-to-tie">Passing the tied object to tie</a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#EXAMPLES">EXAMPLES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#UTILITY-FUNCTIONS">UTILITY FUNCTIONS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#DIAGNOSTICS">DIAGNOSTICS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#BUGS">BUGS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Attribute::Handlers.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./Attribute::Handlers.html#NAME">#</a>NAME</h1>

<p>Attribute::Handlers - Simpler definition of attribute handlers</p>

<h1 id="VERSION"><a class="permalink" href="./Attribute::Handlers.html#VERSION">#</a>VERSION</h1>

<p>This document describes version 1.01 of Attribute::Handlers.</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./Attribute::Handlers.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>    package MyClass;
    require 5.006;
    use Attribute::Handlers;
    no warnings &#39;redefine&#39;;


    sub Good : ATTR(SCALAR) {
	my ($package, $symbol, $referent, $attr, $data) = @_;

	# Invoked for any scalar variable with a :Good attribute,
	# provided the variable was declared in MyClass (or
	# a derived class) or typed to MyClass.

	# Do whatever to $referent here (executed in CHECK phase).
	...
    }

    sub Bad : ATTR(SCALAR) {
	# Invoked for any scalar variable with a :Bad attribute,
	# provided the variable was declared in MyClass (or
	# a derived class) or typed to MyClass.
	...
    }

    sub Good : ATTR(ARRAY) {
	# Invoked for any array variable with a :Good attribute,
	# provided the variable was declared in MyClass (or
	# a derived class) or typed to MyClass.
	...
    }

    sub Good : ATTR(HASH) {
	# Invoked for any hash variable with a :Good attribute,
	# provided the variable was declared in MyClass (or
	# a derived class) or typed to MyClass.
	...
    }

    sub Ugly : ATTR(CODE) {
	# Invoked for any subroutine declared in MyClass (or a 
	# derived class) with an :Ugly attribute.
	...
    }

    sub Omni : ATTR {
	# Invoked for any scalar, array, hash, or subroutine
	# with an :Omni attribute, provided the variable or
	# subroutine was declared in MyClass (or a derived class)
	# or the variable was typed to MyClass.
	# Use ref($_[2]) to determine what kind of referent it was.
	...
    }


    use Attribute::Handlers autotie =&gt; { Cycle =&gt; Tie::Cycle };

    my $next : Cycle([&#39;A&#39;..&#39;Z&#39;]);</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./Attribute::Handlers.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This module, when inherited by a package, allows that package&#39;s class to define attribute handler subroutines for specific attributes. Variables and subroutines subsequently defined in that package, or in packages derived from that package may be given attributes with the same names as the attribute handler subroutines, which will then be called in one of the compilation phases (i.e. in a <code>BEGIN</code>, <code>CHECK</code>, <code>INIT</code>, or <code>END</code> block). (<code>UNITCHECK</code> blocks don&#39;t correspond to a global compilation phase, so they can&#39;t be specified here.)</p>

<p>To create a handler, define it as a subroutine with the same name as the desired attribute, and declare the subroutine itself with the attribute <code>:ATTR</code>. For example:</p>

<pre><code>    package LoudDecl;
    use Attribute::Handlers;

    sub Loud :ATTR {
	my ($package, $symbol, $referent, $attr, $data, $phase,
	    $filename, $linenum) = @_;
	print STDERR
	    ref($referent), &quot; &quot;,
	    *{$symbol}{NAME}, &quot; &quot;,
	    &quot;($referent) &quot;, &quot;was just declared &quot;,
	    &quot;and ascribed the ${attr} attribute &quot;,
	    &quot;with data ($data)\n&quot;,
	    &quot;in phase $phase\n&quot;,
	    &quot;in file $filename at line $linenum\n&quot;;
    }</code></pre>

<p>This creates a handler for the attribute <code>:Loud</code> in the class LoudDecl. Thereafter, any subroutine declared with a <code>:Loud</code> attribute in the class LoudDecl:</p>

<pre><code>package LoudDecl;

sub foo: Loud {...}</code></pre>

<p>causes the above handler to be invoked, and passed:</p>

<dl>

<dt id="[0]"><a class="permalink" href="./Attribute::Handlers.html#%5B0%5D">#</a><a id="pod-0"></a>[0]</dt>
<dd>

<p>the name of the package into which it was declared;</p>

</dd>
<dt id="[1]"><a class="permalink" href="./Attribute::Handlers.html#%5B1%5D">#</a><a id="pod-1"></a>[1]</dt>
<dd>

<p>a reference to the symbol table entry (typeglob) containing the subroutine;</p>

</dd>
<dt id="[2]"><a class="permalink" href="./Attribute::Handlers.html#%5B2%5D">#</a><a id="pod-2"></a>[2]</dt>
<dd>

<p>a reference to the subroutine;</p>

</dd>
<dt id="[3]"><a class="permalink" href="./Attribute::Handlers.html#%5B3%5D">#</a><a id="pod-3"></a>[3]</dt>
<dd>

<p>the name of the attribute;</p>

</dd>
<dt id="[4]"><a class="permalink" href="./Attribute::Handlers.html#%5B4%5D">#</a><a id="pod-4"></a>[4]</dt>
<dd>

<p>any data associated with that attribute;</p>

</dd>
<dt id="[5]"><a class="permalink" href="./Attribute::Handlers.html#%5B5%5D">#</a><a id="pod-5"></a>[5]</dt>
<dd>

<p>the name of the phase in which the handler is being invoked;</p>

</dd>
<dt id="[6]"><a class="permalink" href="./Attribute::Handlers.html#%5B6%5D">#</a><a id="pod-6"></a>[6]</dt>
<dd>

<p>the filename in which the handler is being invoked;</p>

</dd>
<dt id="[7]"><a class="permalink" href="./Attribute::Handlers.html#%5B7%5D">#</a><a id="pod-7"></a>[7]</dt>
<dd>

<p>the line number in this file.</p>

</dd>
</dl>

<p>Likewise, declaring any variables with the <code>:Loud</code> attribute within the package:</p>

<pre><code>package LoudDecl;

my $foo :Loud;
my @foo :Loud;
my %foo :Loud;</code></pre>

<p>will cause the handler to be called with a similar argument list (except, of course, that <code>$_[2]</code> will be a reference to the variable).</p>

<p>The package name argument will typically be the name of the class into which the subroutine was declared, but it may also be the name of a derived class (since handlers are inherited).</p>

<p>If a lexical variable is given an attribute, there is no symbol table to which it belongs, so the symbol table argument (<code>$_[1]</code>) is set to the string <code>&#39;LEXICAL&#39;</code> in that case. Likewise, ascribing an attribute to an anonymous subroutine results in a symbol table argument of <code>&#39;ANON&#39;</code>.</p>

<p>The data argument passes in the value (if any) associated with the attribute. For example, if <code>&amp;foo</code> had been declared:</p>

<pre><code class="plaintext">sub foo :Loud(&quot;turn it up to 11, man!&quot;) {...}</code></pre>

<p>then a reference to an array containing the string <code>&quot;turn it up to 11, man!&quot;</code> would be passed as the last argument.</p>

<p>Attribute::Handlers makes strenuous efforts to convert the data argument (<code>$_[4]</code>) to a usable form before passing it to the handler (but see <a href="./Attribute::Handlers.html#Non-interpretive-attribute-handlers">&quot;Non-interpretive attribute handlers&quot;</a>). If those efforts succeed, the interpreted data is passed in an array reference; if they fail, the raw data is passed as a string. For example, all of these:</p>

<pre><code class="plaintext">sub foo :Loud(till=&gt;ears=&gt;are=&gt;bleeding) {...}
sub foo :Loud(qw/till ears are bleeding/) {...}
sub foo :Loud(qw/till, ears, are, bleeding/) {...}
sub foo :Loud(till,ears,are,bleeding) {...}</code></pre>

<p>causes it to pass <code>[&#39;till&#39;,&#39;ears&#39;,&#39;are&#39;,&#39;bleeding&#39;]</code> as the handler&#39;s data argument. While:</p>

<pre><code class="plaintext">sub foo :Loud([&#39;till&#39;,&#39;ears&#39;,&#39;are&#39;,&#39;bleeding&#39;]) {...}</code></pre>

<p>causes it to pass <code>[ [&#39;till&#39;,&#39;ears&#39;,&#39;are&#39;,&#39;bleeding&#39;] ]</code>; the array reference specified in the data being passed inside the standard array reference indicating successful interpretation.</p>

<p>However, if the data can&#39;t be parsed as valid Perl, then it is passed as an uninterpreted string. For example:</p>

<pre><code class="plaintext">sub foo :Loud(my,ears,are,bleeding) {...}
sub foo :Loud(qw/my ears are bleeding) {...}</code></pre>

<p>cause the strings <code>&#39;my,ears,are,bleeding&#39;</code> and <code>&#39;qw/my ears are bleeding&#39;</code> respectively to be passed as the data argument.</p>

<p>If no value is associated with the attribute, <code>undef</code> is passed.</p>

<h2 id="Typed-lexicals"><a class="permalink" href="./Attribute::Handlers.html#Typed-lexicals">#</a><a id="Typed"></a>Typed lexicals</h2>

<p>Regardless of the package in which it is declared, if a lexical variable is ascribed an attribute, the handler that is invoked is the one belonging to the package to which it is typed. For example, the following declarations:</p>

<pre><code>package OtherClass;

my LoudDecl $loudobj : Loud;
my LoudDecl @loudobjs : Loud;
my LoudDecl %loudobjex : Loud;</code></pre>

<p>causes the LoudDecl::Loud handler to be invoked (even if OtherClass also defines a handler for <code>:Loud</code> attributes).</p>

<h2 id="Type-specific-attribute-handlers"><a class="permalink" href="./Attribute::Handlers.html#Type-specific-attribute-handlers">#</a><a id="Type"></a>Type-specific attribute handlers</h2>

<p>If an attribute handler is declared and the <code>:ATTR</code> specifier is given the name of a built-in type (<code>SCALAR</code>, <code>ARRAY</code>, <code>HASH</code>, or <code>CODE</code>), the handler is only applied to declarations of that type. For example, the following definition:</p>

<pre><code>package LoudDecl;

sub RealLoud :ATTR(SCALAR) { print &quot;Yeeeeow!&quot; }</code></pre>

<p>creates an attribute handler that applies only to scalars:</p>

<pre><code>package Painful;
use base LoudDecl;

my $metal : RealLoud;           # invokes &amp;LoudDecl::RealLoud
my @metal : RealLoud;           # error: unknown attribute
my %metal : RealLoud;           # error: unknown attribute
sub metal : RealLoud {...}      # error: unknown attribute</code></pre>

<p>You can, of course, declare separate handlers for these types as well (but you&#39;ll need to specify <code>no warnings &#39;redefine&#39;</code> to do it quietly):</p>

<pre><code>package LoudDecl;
use Attribute::Handlers;
no warnings &#39;redefine&#39;;

sub RealLoud :ATTR(SCALAR) { print &quot;Yeeeeow!&quot; }
sub RealLoud :ATTR(ARRAY) { print &quot;Urrrrrrrrrr!&quot; }
sub RealLoud :ATTR(HASH) { print &quot;Arrrrrgggghhhhhh!&quot; }
sub RealLoud :ATTR(CODE) { croak &quot;Real loud sub torpedoed&quot; }</code></pre>

<p>You can also explicitly indicate that a single handler is meant to be used for all types of referents like so:</p>

<pre><code>package LoudDecl;
use Attribute::Handlers;

sub SeriousLoud :ATTR(ANY) { warn &quot;Hearing loss imminent&quot; }</code></pre>

<p>(I.e. <code>ATTR(ANY)</code> is a synonym for <code>:ATTR</code>).</p>

<h2 id="Non-interpretive-attribute-handlers"><a class="permalink" href="./Attribute::Handlers.html#Non-interpretive-attribute-handlers">#</a><a id="Non"></a>Non-interpretive attribute handlers</h2>

<p>Occasionally the strenuous efforts Attribute::Handlers makes to convert the data argument (<code>$_[4]</code>) to a usable form before passing it to the handler get in the way.</p>

<p>You can turn off that eagerness-to-help by declaring an attribute handler with the keyword <code>RAWDATA</code>. For example:</p>

<pre><code class="plaintext">sub Raw          : ATTR(RAWDATA) {...}
sub Nekkid       : ATTR(SCALAR,RAWDATA) {...}
sub Au::Naturale : ATTR(RAWDATA,ANY) {...}</code></pre>

<p>Then the handler makes absolutely no attempt to interpret the data it receives and simply passes it as a string:</p>

<pre><code>my $power : Raw(1..100);        # handlers receives &quot;1..100&quot;</code></pre>

<h2 id="Phase-specific-attribute-handlers"><a class="permalink" href="./Attribute::Handlers.html#Phase-specific-attribute-handlers">#</a><a id="Phase"></a>Phase-specific attribute handlers</h2>

<p>By default, attribute handlers are called at the end of the compilation phase (in a <code>CHECK</code> block). This seems to be optimal in most cases because most things that can be defined are defined by that point but nothing has been executed.</p>

<p>However, it is possible to set up attribute handlers that are called at other points in the program&#39;s compilation or execution, by explicitly stating the phase (or phases) in which you wish the attribute handler to be called. For example:</p>

<pre><code class="plaintext">sub Early    :ATTR(SCALAR,BEGIN) {...}
sub Normal   :ATTR(SCALAR,CHECK) {...}
sub Late     :ATTR(SCALAR,INIT) {...}
sub Final    :ATTR(SCALAR,END) {...}
sub Bookends :ATTR(SCALAR,BEGIN,END) {...}</code></pre>

<p>As the last example indicates, a handler may be set up to be (re)called in two or more phases. The phase name is passed as the handler&#39;s final argument.</p>

<p>Note that attribute handlers that are scheduled for the <code>BEGIN</code> phase are handled as soon as the attribute is detected (i.e. before any subsequently defined <code>BEGIN</code> blocks are executed).</p>

<h2 id="Attributes-as-tie-interfaces"><a class="permalink" href="./Attribute::Handlers.html#Attributes-as-tie-interfaces">#</a><a id="Attributes"></a>Attributes as <code>tie</code> interfaces</h2>

<p>Attributes make an excellent and intuitive interface through which to tie variables. For example:</p>

<pre><code>    use Attribute::Handlers;
    use Tie::Cycle;

    sub UNIVERSAL::Cycle : ATTR(SCALAR) {
	my ($package, $symbol, $referent, $attr, $data, $phase) = @_;
	$data = [ $data ] unless ref $data eq &#39;ARRAY&#39;;
	tie $$referent, &#39;Tie::Cycle&#39;, $data;
    }

    # and thereafter...

    package main;

    my $next : Cycle(&#39;A&#39;..&#39;Z&#39;);     # $next is now a tied variable

    while (&lt;&gt;) {
	print $next;
    }</code></pre>

<p>Note that, because the <code>Cycle</code> attribute receives its arguments in the <code>$data</code> variable, if the attribute is given a list of arguments, <code>$data</code> will consist of a single array reference; otherwise, it will consist of the single argument directly. Since Tie::Cycle requires its cycling values to be passed as an array reference, this means that we need to wrap non-array-reference arguments in an array constructor:</p>

<pre><code>$data = [ $data ] unless ref $data eq &#39;ARRAY&#39;;</code></pre>

<p>Typically, however, things are the other way around: the tieable class expects its arguments as a flattened list, so the attribute looks like:</p>

<pre><code>    sub UNIVERSAL::Cycle : ATTR(SCALAR) {
	my ($package, $symbol, $referent, $attr, $data, $phase) = @_;
	my @data = ref $data eq &#39;ARRAY&#39; ? @$data : $data;
	tie $$referent, &#39;Tie::Whatever&#39;, @data;
    }</code></pre>

<p>This software pattern is so widely applicable that Attribute::Handlers provides a way to automate it: specifying <code>&#39;autotie&#39;</code> in the <code>use Attribute::Handlers</code> statement. So, the cycling example, could also be written:</p>

<pre><code>    use Attribute::Handlers autotie =&gt; { Cycle =&gt; &#39;Tie::Cycle&#39; };

    # and thereafter...

    package main;

    my $next : Cycle([&#39;A&#39;..&#39;Z&#39;]);     # $next is now a tied variable

    while (&lt;&gt;) {
	print $next;
    }</code></pre>

<p>Note that we now have to pass the cycling values as an array reference, since the <code>autotie</code> mechanism passes <code>tie</code> a list of arguments as a list (as in the Tie::Whatever example), <i>not</i> as an array reference (as in the original Tie::Cycle example at the start of this section).</p>

<p>The argument after <code>&#39;autotie&#39;</code> is a reference to a hash in which each key is the name of an attribute to be created, and each value is the class to which variables ascribed that attribute should be tied.</p>

<p>Note that there is no longer any need to import the Tie::Cycle module -- Attribute::Handlers takes care of that automagically. You can even pass arguments to the module&#39;s <code>import</code> subroutine, by appending them to the class name. For example:</p>

<pre><code>    use Attribute::Handlers
	 autotie =&gt; { Dir =&gt; &#39;Tie::Dir qw(DIR_UNLINK)&#39; };</code></pre>

<p>If the attribute name is unqualified, the attribute is installed in the current package. Otherwise it is installed in the qualifier&#39;s package:</p>

<pre><code>package Here;

use Attribute::Handlers autotie =&gt; {
     Other::Good =&gt; Tie::SecureHash, # tie attr installed in Other::
             Bad =&gt; Tie::Taxes,      # tie attr installed in Here::
 UNIVERSAL::Ugly =&gt; Software::Patent # tie attr installed everywhere
};</code></pre>

<p>Autoties are most commonly used in the module to which they actually tie, and need to export their attributes to any module that calls them. To facilitate this, Attribute::Handlers recognizes a special &quot;pseudo-class&quot; -- <code>__CALLER__</code>, which may be specified as the qualifier of an attribute:</p>

<pre><code>    package Tie::Me::Kangaroo:Down::Sport;

    use Attribute::Handlers autotie =&gt;
	 { &#39;__CALLER__::Roo&#39; =&gt; __PACKAGE__ };</code></pre>

<p>This causes Attribute::Handlers to define the <code>Roo</code> attribute in the package that imports the Tie::Me::Kangaroo:Down::Sport module.</p>

<p>Note that it is important to quote the __CALLER__::Roo identifier because a bug in perl 5.8 will refuse to parse it and cause an unknown error.</p>

<h3 id="Passing-the-tied-object-to-tie"><a class="permalink" href="./Attribute::Handlers.html#Passing-the-tied-object-to-tie">#</a><a id="Passing"></a>Passing the tied object to <code>tie</code></h3>

<p>Occasionally it is important to pass a reference to the object being tied to the TIESCALAR, TIEHASH, etc. that ties it.</p>

<p>The <code>autotie</code> mechanism supports this too. The following code:</p>

<pre><code>use Attribute::Handlers autotieref =&gt; { Selfish =&gt; Tie::Selfish };
my $var : Selfish(@args);</code></pre>

<p>has the same effect as:</p>

<pre><code>tie my $var, &#39;Tie::Selfish&#39;, @args;</code></pre>

<p>But when <code>&quot;autotieref&quot;</code> is used instead of <code>&quot;autotie&quot;</code>:</p>

<pre><code>use Attribute::Handlers autotieref =&gt; { Selfish =&gt; Tie::Selfish };
my $var : Selfish(@args);</code></pre>

<p>the effect is to pass the <code>tie</code> call an extra reference to the variable being tied:</p>

<pre><code>tie my $var, &#39;Tie::Selfish&#39;, \$var, @args;</code></pre>

<h1 id="EXAMPLES"><a class="permalink" href="./Attribute::Handlers.html#EXAMPLES">#</a>EXAMPLES</h1>

<p>If the class shown in <a href="./Attribute::Handlers.html#SYNOPSIS">&quot;SYNOPSIS&quot;</a> were placed in the MyClass.pm module, then the following code:</p>

<pre><code>package main;
use MyClass;

my MyClass $slr :Good :Bad(1**1-1) :Omni(-vorous);

package SomeOtherClass;
use base MyClass;

sub tent { &#39;acle&#39; }

sub fn :Ugly(sister) :Omni(&#39;po&#39;,tent()) {...}
my @arr :Good :Omni(s/cie/nt/);
my %hsh :Good(q/bye/) :Omni(q/bus/);</code></pre>

<p>would cause the following handlers to be invoked:</p>

<pre><code># my MyClass $slr :Good :Bad(1**1-1) :Omni(-vorous);

MyClass::Good:ATTR(SCALAR)( &#39;MyClass&#39;,          # class
                            &#39;LEXICAL&#39;,          # no typeglob
                            \$slr,              # referent
                            &#39;Good&#39;,             # attr name
                            undef               # no attr data
                            &#39;CHECK&#39;,            # compiler phase
                          );

MyClass::Bad:ATTR(SCALAR)( &#39;MyClass&#39;,           # class
                           &#39;LEXICAL&#39;,           # no typeglob
                           \$slr,               # referent
                           &#39;Bad&#39;,               # attr name
                           0                    # eval&#39;d attr data
                           &#39;CHECK&#39;,             # compiler phase
                         );

MyClass::Omni:ATTR(SCALAR)( &#39;MyClass&#39;,          # class
                            &#39;LEXICAL&#39;,          # no typeglob
                            \$slr,              # referent
                            &#39;Omni&#39;,             # attr name
                            &#39;-vorous&#39;           # eval&#39;d attr data
                            &#39;CHECK&#39;,            # compiler phase
                          );


# sub fn :Ugly(sister) :Omni(&#39;po&#39;,tent()) {...}

MyClass::UGLY:ATTR(CODE)( &#39;SomeOtherClass&#39;,     # class
                          \*SomeOtherClass::fn, # typeglob
                          \&amp;SomeOtherClass::fn, # referent
                          &#39;Ugly&#39;,               # attr name
                          &#39;sister&#39;              # eval&#39;d attr data
                          &#39;CHECK&#39;,              # compiler phase
                        );

MyClass::Omni:ATTR(CODE)( &#39;SomeOtherClass&#39;,     # class
                          \*SomeOtherClass::fn, # typeglob
                          \&amp;SomeOtherClass::fn, # referent
                          &#39;Omni&#39;,               # attr name
                          [&#39;po&#39;,&#39;acle&#39;]         # eval&#39;d attr data
                          &#39;CHECK&#39;,              # compiler phase
                        );


# my @arr :Good :Omni(s/cie/nt/);

MyClass::Good:ATTR(ARRAY)( &#39;SomeOtherClass&#39;,    # class
                           &#39;LEXICAL&#39;,           # no typeglob
                           \@arr,               # referent
                           &#39;Good&#39;,              # attr name
                           undef                # no attr data
                           &#39;CHECK&#39;,             # compiler phase
                         );

MyClass::Omni:ATTR(ARRAY)( &#39;SomeOtherClass&#39;,    # class
                           &#39;LEXICAL&#39;,           # no typeglob
                           \@arr,               # referent
                           &#39;Omni&#39;,              # attr name
                           &quot;&quot;                   # eval&#39;d attr data 
                           &#39;CHECK&#39;,             # compiler phase
                         );


# my %hsh :Good(q/bye) :Omni(q/bus/);

MyClass::Good:ATTR(HASH)( &#39;SomeOtherClass&#39;,     # class
                          &#39;LEXICAL&#39;,            # no typeglob
                          \%hsh,                # referent
                          &#39;Good&#39;,               # attr name
                          &#39;q/bye&#39;               # raw attr data
                          &#39;CHECK&#39;,              # compiler phase
                        );

MyClass::Omni:ATTR(HASH)( &#39;SomeOtherClass&#39;,     # class
                          &#39;LEXICAL&#39;,            # no typeglob
                          \%hsh,                # referent
                          &#39;Omni&#39;,               # attr name
                          &#39;bus&#39;                 # eval&#39;d attr data
                          &#39;CHECK&#39;,              # compiler phase
                        );</code></pre>

<p>Installing handlers into UNIVERSAL, makes them...err..universal. For example:</p>

<pre><code>package Descriptions;
use Attribute::Handlers;

my %name;
sub name { return $name{$_[2]}||*{$_[1]}{NAME} }

sub UNIVERSAL::Name :ATTR {
    $name{$_[2]} = $_[4];
}

sub UNIVERSAL::Purpose :ATTR {
    print STDERR &quot;Purpose of &quot;, &amp;name, &quot; is $_[4]\n&quot;;
}

sub UNIVERSAL::Unit :ATTR {
    print STDERR &amp;name, &quot; measured in $_[4]\n&quot;;
}</code></pre>

<p>Let&#39;s you write:</p>

<pre><code>use Descriptions;

my $capacity : Name(capacity)
             : Purpose(to store max storage capacity for files)
             : Unit(Gb);


package Other;

sub foo : Purpose(to foo all data before barring it) { }

# etc.</code></pre>

<h1 id="UTILITY-FUNCTIONS"><a class="permalink" href="./Attribute::Handlers.html#UTILITY-FUNCTIONS">#</a><a id="UTILITY"></a>UTILITY FUNCTIONS</h1>

<p>This module offers a single utility function, <code>findsym()</code>.</p>

<dl>

<dt id="findsym"><a class="permalink" href="./Attribute::Handlers.html#findsym">#</a>findsym</dt>
<dd>

<pre><code>my $symbol = Attribute::Handlers::findsym($package, $referent);</code></pre>

<p>The function looks in the symbol table of <code>$package</code> for the typeglob for <code>$referent</code>, which is a reference to a variable or subroutine (SCALAR, ARRAY, HASH, or CODE). If it finds the typeglob, it returns it. Otherwise, it returns undef. Note that <code>findsym</code> memoizes the typeglobs it has previously successfully found, so subsequent calls with the same arguments should be much faster.</p>

</dd>
</dl>

<h1 id="DIAGNOSTICS"><a class="permalink" href="./Attribute::Handlers.html#DIAGNOSTICS">#</a>DIAGNOSTICS</h1>

<dl>

<dt id="Bad-attribute-type:-ATTR(%s)"><a class="permalink" href="./Attribute::Handlers.html#Bad-attribute-type:-ATTR(%25s)">#</a><a id="Bad"></a><a id="Bad-attribute-type:-ATTR-s"></a><code>Bad attribute type: ATTR(%s)</code></dt>
<dd>

<p>An attribute handler was specified with an <code>:ATTR(<i>ref_type</i>)</code>, but the type of referent it was defined to handle wasn&#39;t one of the five permitted: <code>SCALAR</code>, <code>ARRAY</code>, <code>HASH</code>, <code>CODE</code>, or <code>ANY</code>.</p>

</dd>
<dt id="Attribute-handler-%s-doesn&#39;t-handle-%s-attributes"><a class="permalink" href="./Attribute::Handlers.html#Attribute-handler-%25s-doesn&#39;t-handle-%25s-attributes">#</a><a id="Attribute"></a><a id="Attribute-handler-s-doesnt-handle-s-attributes"></a><code>Attribute handler %s doesn&#39;t handle %s attributes</code></dt>
<dd>

<p>A handler for attributes of the specified name <i>was</i> defined, but not for the specified type of declaration. Typically encountered when trying to apply a <code>VAR</code> attribute handler to a subroutine, or a <code>SCALAR</code> attribute handler to some other type of variable.</p>

</dd>
<dt id="Declaration-of-%s-attribute-in-package-%s-may-clash-with-future-reserved-word"><a class="permalink" href="./Attribute::Handlers.html#Declaration-of-%25s-attribute-in-package-%25s-may-clash-with-future-reserved-word">#</a><a id="Declaration"></a><a id="Declaration-of-s-attribute-in-package-s-may-clash-with-future-reserved-word"></a><code>Declaration of %s attribute in package %s may clash with future reserved word</code></dt>
<dd>

<p>A handler for an attributes with an all-lowercase name was declared. An attribute with an all-lowercase name might have a meaning to Perl itself some day, even though most don&#39;t yet. Use a mixed-case attribute name, instead.</p>

</dd>
<dt id="Can&#39;t-have-two-ATTR-specifiers-on-one-subroutine"><a class="permalink" href="./Attribute::Handlers.html#Can&#39;t-have-two-ATTR-specifiers-on-one-subroutine">#</a><a id="Can"></a><a id="Cant-have-two-ATTR-specifiers-on-one-subroutine"></a><code>Can&#39;t have two ATTR specifiers on one subroutine</code></dt>
<dd>

<p>You just can&#39;t, okay? Instead, put all the specifications together with commas between them in a single <code>ATTR(<i>specification</i>)</code>.</p>

</dd>
<dt id="Can&#39;t-autotie-a-%s"><a class="permalink" href="./Attribute::Handlers.html#Can&#39;t-autotie-a-%25s">#</a><a id="Can1"></a><a id="Cant-autotie-a-s"></a><code>Can&#39;t autotie a %s</code></dt>
<dd>

<p>You can only declare autoties for types <code>&quot;SCALAR&quot;</code>, <code>&quot;ARRAY&quot;</code>, and <code>&quot;HASH&quot;</code>. They&#39;re the only things (apart from typeglobs -- which are not declarable) that Perl can tie.</p>

</dd>
<dt id="Internal-error:-%s-symbol-went-missing"><a class="permalink" href="./Attribute::Handlers.html#Internal-error:-%25s-symbol-went-missing">#</a><a id="Internal"></a><a id="Internal-error:-s-symbol-went-missing"></a><code>Internal error: %s symbol went missing</code></dt>
<dd>

<p>Something is rotten in the state of the program. An attributed subroutine ceased to exist between the point it was declared and the point at which its attribute handler(s) would have been called.</p>

</dd>
<dt id="Won&#39;t-be-able-to-apply-END-handler"><a class="permalink" href="./Attribute::Handlers.html#Won&#39;t-be-able-to-apply-END-handler">#</a><a id="Won"></a><a id="Wont-be-able-to-apply-END-handler"></a><code>Won&#39;t be able to apply END handler</code></dt>
<dd>

<p>You have defined an END handler for an attribute that is being applied to a lexical variable. Since the variable may not be available during END this won&#39;t happen.</p>

</dd>
</dl>

<h1 id="AUTHOR"><a class="permalink" href="./Attribute::Handlers.html#AUTHOR">#</a>AUTHOR</h1>

<p>Damian Conway (damian@conway.org). The maintainer of this module is now Rafael Garcia-Suarez (rgarciasuarez@gmail.com).</p>

<p>Maintainer of the CPAN release is Steffen Mueller (smueller@cpan.org). Contact him with technical difficulties with respect to the packaging of the CPAN module.</p>

<h1 id="BUGS"><a class="permalink" href="./Attribute::Handlers.html#BUGS">#</a>BUGS</h1>

<p>There are undoubtedly serious bugs lurking somewhere in code this funky :-) Bug reports and other feedback are most welcome.</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a class="permalink" href="./Attribute::Handlers.html#COPYRIGHT-AND-LICENSE">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<pre><code class="plaintext">  Copyright (c) 2001-2014, Damian Conway. All Rights Reserved.
This module is free software. It may be used, redistributed
    and/or modified under the same terms as Perl itself.</code></pre>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
